﻿using System.ComponentModel;
using System.Windows;

namespace NoRefsTest.Client
{
	public abstract class ViewModelBase : INotifyPropertyChanged
	{
		public static bool IsDesignMode
		{
			get { return (bool) (DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof (DependencyObject)).DefaultValue); }
		}

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		#endregion

		protected virtual void RaisePropertyChanged(string propertyName)
		{
			var handler = PropertyChanged;
			if (handler == null) return;
			handler(this, new PropertyChangedEventArgs(propertyName));
		}

		protected virtual bool SetFieldValue<T>(ref T field, T value, string propertyName)
		{
			if (Equals(field, value)) return false;
			field = value;
			RaisePropertyChanged(propertyName);
			return true;
		}
	}
}